
package com.dstz.form.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * xianggang
 */
public class Util {
	
	public static <T> Map<String, T> map(String key, T value) {
		Map<String, T> map = new HashMap<>();
		map.put(key, value);
		return map;
	}
	
	@SuppressWarnings("unchecked")
	public static <T> List<T> list(T... value) {
		if (value == null) {
			return null;
		}
		List<T> list = new ArrayList<>();
		for (T t : value) {
			list.add(t);
		}
		return list;
	}
	
	@SuppressWarnings("unchecked")
	public static <T> T[] array(T... value) {
		return value;
	}
	
	public static int[] intArray(int... value) {
		return value;
	}
	
	@SuppressWarnings("unchecked")
	public static <T> Set<T> set(T... value) {
		if (value == null) {
			return null;
		}
		Set<T> set = new HashSet<>();
		for (T t : value) {
			set.add(t);
		}
		return set;
	}
	
	@SuppressWarnings("unchecked")
	public static <T> boolean contains(Object data, T... compareDatas) {
		Set<T> set = set(compareDatas);
		if (set == null) {
			return false;
		}
		return set.contains(data);
	}
	
	public static boolean isEqual(Object data1, Object data2) {
		if (data1 == null && data2 == null) {
			return true;
		}
		if (data1 == null) {
			return false;
		}
		if (data2 == null) {
			return false;
		}
		return data1.toString().equals(data2.toString());
	}
	
	public static boolean equals(Object data1, Object data2) {
		return isEqual(data1, data2);
	}
}
